package server.game.players.packets;

/**
 * @author Ryan / Lmctruck30
 */

import server.game.items.UseItem;
import server.content.skills.*;
import server.game.players.Client;
import server.game.players.PacketType;

public class ItemOnObject implements PacketType {

	@Override
	public void processPacket(Client c, int packetType, int packetSize) {
		/*
		 * a = ? b = ?
		 */

		int a = c.getInStream().readUnsignedWord();
		int objectId = c.getInStream().readSignedWordBigEndian();
		int objectY = c.getInStream().readSignedWordBigEndianA();
		int b = c.getInStream().readUnsignedWord();
		int objectX = c.getInStream().readSignedWordBigEndianA();
		int itemId = c.getInStream().readUnsignedWord();
		if (!c.getItems().playerHasItem(itemId, 1)) {
			return;
		}
		c.cookingCoords[0] = objectX;
		c.cookingCoords[1] = objectY;
		c.turnPlayerTo(objectX, objectY);
		UseItem.ItemonObject(c, objectId, objectX, objectY, itemId);
		switch (objectId) {
		case 879:
		case 874:
		case 14868:
		case 884:
			if (c.goodDistance(c.getX(), c.getY(), objectX, objectY, 2)) {
				c.turnPlayerTo(objectX, objectY);
				if (c.getItems().playerHasItem(229)) {
					c.filling.attempt(objectId);
				}
			}
			break;
		case 1804:
			if (c.objectX == 3115 && c.objectY == 3450) {
				if (c.getItems().playerHasItem(983) && itemId == 983) {
					if (c.getY() < 3450) {
						c.sendMessage("You open the door and leave...");
						c.getPA().movePlayer(c.getX(), 3450, 0);
					} else if (c.getY() > 3449) {
						c.sendMessage("You open the door and enter...");
						c.getPA().movePlayer(c.getX(), 3449, 0);
					}
				}
			}
			break;

		case 2452:
		case 2453:
		case 2454:
		case 2455:
		case 2456:
		case 2457:
		case 2458:
		case 2459:
		case 2460:
		case 2461:
		case 2462:
			c.getRunecrafting().enterAltar(objectId, itemId);
			break;
		case 12269:
		case 2732:
		case 114:
		case 9374:
		case 2728:
		case 25465:
		case 11404:
		case 11405:
		case 11406:
			Cooking.cookThisFood(c, itemId, objectId);
			break;
		}

	}
}
